<template>
  <div class="card shadow" :class="type === 'dark' ? 'bg-default' : ''">
    <div
      class="card-header border-0"
      :class="type === 'dark' ? 'bg-transparent' : ''"
    >
      <div class="row align-items-center">
        <div class="col-md-8">
          <base-button outline type="secondary">
            <i class="ni ni-bullet-list-67"></i>
            {{ title }}
          </base-button>
          <base-button type="success" @click="bindSave()">
            <i class="ni ni-fat-add"></i>添加每日一句
          </base-button>
        </div>
        <div class="col-md-4">
          <div class="input-group">
            <input
              type="text"
              placeholder="请输入标题关键字进行搜索..."
              class="form-control"
              valid="true"
              @input="search()"
              v-model="searchKey"
            />
          </div>
        </div>
      </div>
    </div>

    <div class="table-responsive">
      <base-table
        class="table align-items-center table-flush"
        :class="type === 'dark' ? 'table-dark' : ''"
        :thead-classes="type === 'dark' ? 'thead-dark' : 'thead-light'"
        tbody-classes="list"
        :data="tableData"
      >
        <template slot="columns">
          <th></th>
          <th>当前推荐</th>
          <th>一句</th>
          <th>作者</th>
          <th>总分享</th>
          <th>总表扬</th>
          <th>更新时间</th>
          <th>状态</th>
          <th>操作</th>
        </template>

        <template slot-scope="{ row }">
          <td></td>
          <td class="budget">{{ row.recommend }}</td>
          <td class="badge-dot mr-4">{{ row.sentence }}</td>
          <td class="budget">{{ row.authornick }}</td>
          <td class="budget">{{ row.gsharecount }}</td>
          <td class="budget">{{ row.gbiaoyang }}</td>
          <td class="badge-dot mr-4">{{ row.updatetime }}</td>
          <td class="avatar-group">{{ row.status }}</td>
          <td>
            <div class="d-flex align-items-center">
              <base-button
                outline
                type="primary"
                @click="bindEdit(row.id)"
                size="sm"
                >编辑</base-button
              >
              <base-button
                outline
                type="warning"
                @click="bindDel(row.id)"
                size="sm"
                >删除</base-button
              >
            </div>
          </td>
        </template>
      </base-table>
    </div>

    <div class="card-footer d-flex justify-content-center">
      <div class="col-md-2"></div>
      <div class="col-md-8">
        <base-pagination
          :value="pageList.newPageValue"
          :total="pageList.totalRecords"
          :page-count="pageList.totalPages"
          @input="page(arguments)"
          ref="pagechild"
          align="center"
        ></base-pagination>
      </div>
      <div class="col-md-2"></div>
    </div>
  </div>
</template>
<script>
import { findRjSentByPageApi } from "~/config/api/rjeverydaysentenceservice";
import { delRjSentApi } from "~/config/api/rjeverydaysentenceservice";
import dateTools from "~/config/utils/date-tools";
import tableDataTools from "~/config/utils/tabledata-tools";
export default {
  name: "projects-table",
  props: {
    type: {
      type: String,
    },
    title: String,
  },
  data() {
    return {
      searchKey: "",
      tableData: [
        {
          id: 1,
          recommend: "推荐",
          sentence: "一句",
          authornick: "作者",
          gbiaoyang: 0,
          gsharecount: 0,
          updatetime: 1970 - 1 - 1,
          status: "启用",
        },
      ],
      pageList: {
        totalRecords: 100,
        totalPages: 10,
        newPageValue: 1,
        perPageSize: 10,
      },
    };
  },
  mounted() {
    this.findRjSentByPageList();
  },
  methods: {
    search: function () {
      this.findRjSentByPageList();
    },
    page: function (args) {
      this.pageList.newPageValue = args[0];
      this.findRjSentByPageList();
    },

    async findRjSentByPageList() {
      let params = {
        start: this.pageList.newPageValue,
        length: this.pageList.perPageSize,
        searchKey: this.searchKey,
      };
      await findRjSentByPageApi(params).then((res) => {
        if (res.sucflag) {
          this.pageList.totalRecords = res.totalrecords;
          this.pageList.totalPages = res.totalPage;
          let datalist = [];
          let bl = res.beanlist;
          for (let i in bl) {
            let data = {
              id: bl[i].id,
              gbiaoyang: bl[i].gbiaoyang,
              gsharecount: bl[i].gsharecount,
              authornick: bl[i].authornick,
              sentence: bl[i].sentence,
              recommend: bl[i].recommend,
              updatetime: dateTools.formatDateTimeLongToStr(bl[i].updatetime),
              status: tableDataTools.filterStatus(bl[i].status),
            };
            datalist.push(data);
          }
          this.tableData = datalist;
        }
      });
    },

    bindSave: function () {
      this.$router.push({
        name: "riji-rjeverysentence",
        query: { action: "save" },
      });
    },

    bindEdit: function (id) {
      this.$router.push({
        name: "riji-rjeverysentence",
        query: { action: "edit", id: id },
      });
    },
    bindDel: function (id) {},
  },
};
</script>
<style>
</style>